/*******************************************************************************
Paper title: Does early nutrition predict cognitive skills during later childhood?
Evidence from two developing countries
Alan Sanchez, Marta Favara, Margaret Sheridan, Jere Behrman.
Created: 8 OCt 2020
This version: 4 Dec 2023 
Structure: Estimations related to nutrition use observed HAZ/stunting and OLS methods
Content: Table 4 (panel A), Table 5 (panel A), Table C4, Table C5	
*******************************************************************************/
			
clear all
local user Alan

if "`user'"=="Alan" {
global outdata	C:\Users\alans\Dropbox\_NIHR21_Proposal\NIH Papers\Paper 1_nutrition&EF\paper\WD\Replication files\Data
global output   C:\Users\alans\Dropbox\_NIHR21_Proposal\NIH Papers\Paper 1_nutrition&EF\paper\WD\Replication files\Output
}

global control0   chage_r4 chage_r4_2 female dm_educ2 dm_educ3 dm_educ4 urban_c hhsize_c
global country1   mom_spanish
global country2   mom_oromifa mom_tigrina mom_other
global control2q  wi_cq2 wi_cq3 wi_cq4 wi_cq5
global alltask 	  hr2 hr3 wkend /*practices*/
global cluster_r1 sib_y sib_o /*dclustid_r11- dclustid_r120*/

global control0xf  i.female*chage_r4 i.female*chage_r4_2 i.female*dm_educ2 ///
                   i.female*dm_educ3 i.female*dm_educ4 i.female*urban_c i.female*hhsize_c
global control2qf  i.female*wi_cq2 i.female*wi_cq3 i.female*wi_cq4 i.female*wi_cq5  
global country1f   i.female*mom_spanish 
global country2f   i.female*mom_oromifa i.female*mom_tigrina i.female*mom_other
global alltaskf    i.female*hr2 i.female*hr3 i.female*wkend /*i.female*practices*/
global cluster_r1f i.female*sib_y i.female*sib_o

global control0xa  chage_r4xdm_educ2 chage_r4xdm_educ3 chage_r4xdm_educ4 ///
                   chage_r4xurban_c chage_r4xhhsize_c
global control2qa  chage_r4xwi_cq2 chage_r4xwi_cq3 chage_r4xwi_cq4 chage_r4xwi_cq5  
global country1a   chage_r4xmom_spanish 
global country2a   chage_r4xmom_oromifa chage_r4xmom_tigrina chage_r4xmom_other
global alltaska    chage_r4xhr2 chage_r4xhr3 chage_r4xwkend /*chage_r4xpractices*/
global cluster_r1a chage_r4xsib_y chage_r4xsib_o

global task1 	task1
global task2 	itask2_a
global task3 	itask3
global task4 	itask4	

global btask1 	btask1
global btask2 	bitask2_a
global btask3 	bitask3
global btask4 	bitask4	

global sample1  zhfa_c<=6 & zhfa_c>=-6
global sample2  zhfa_c<=6 & zhfa_c>=-6

global absorb   clustid_r1
global indlevel pride_index_r4 agency_index_r4 sesteem_index_r4 ppvtz_r4 missing_ppvt

*---------------------------------------------------------------------------------------------------------------------*---------------------------------------------------------------------------------------------------------------------*------------------------------------------------------------------------------------------------------------------*/

use "$outdata\pe_et_childlevel_230821", clear
sort childid sibling
merge childid sibling using "$outdata\et_ppvt_r2"
tab _merge
drop if _merge==2
drop _merge

sort childid sibling
merge childid sibling using "$outdata\pe_ppvt_r2"
tab _merge
drop if _merge==2
drop _merge

sort childid sibling
merge childid sibling using "$outdata\et_ppvt_r3"
tab _merge
drop if _merge==2
drop _merge

sort childid sibling
merge childid sibling using "$outdata\pe_ppvt_r3"
tab _merge
drop if _merge==2
drop _merge

sort childid sibling
merge childid sibling using "$outdata\et_cppvt_r3"
tab _merge
drop if _merge==2
drop _merge

sort childid sibling
merge childid sibling using "$outdata\pe_cppvt_r3"
tab _merge
drop if _merge==2
drop _merge

*** STANDARDIZING PPVT FROM ROUND 2 (FOR INDEX CHILDREN)
gen  std_pe_ppvtr2=.
egen std_pe_ppvtr2_4=std(pe_ppvt_r2) if pe_ppvt_r2<60  & pe_ppvt_r2!=.
egen std_pe_ppvtr2_5=std(pe_ppvt_r2) if pe_ppvt_r2>=60 & pe_ppvt_r2!=.
***
replace std_pe_ppvtr2=std_pe_ppvtr2_4 if std_pe_ppvtr2_4!=.
replace std_pe_ppvtr2=std_pe_ppvtr2_5 if std_pe_ppvtr2_5!=.

gen  std_et_ppvtr2=.
egen std_et_ppvtr2_4=std(et_ppvt_r2) if et_ppvt_r2<60  & et_ppvt_r2!=.
egen std_et_ppvtr2_5=std(et_ppvt_r2) if et_ppvt_r2>=60 & et_ppvt_r2!=.
***
replace std_et_ppvtr2=std_et_ppvtr2_4 if std_et_ppvtr2_4!=.
replace std_et_ppvtr2=std_et_ppvtr2_5 if std_et_ppvtr2_5!=.

*** STANDARDIZING PPVT FROM ROUND 3 (FOR SIBLINGS)
gen  std_pe_ppvtr3=.
egen std_pe_ppvtr3_3=std(pe_ppvt_r3) if pe_ppvt_r3<48                  & pe_ppvt_r3!=.
egen std_pe_ppvtr3_4=std(pe_ppvt_r3) if pe_ppvt_r3>=48 & pe_ppvt_r3<60 & pe_ppvt_r3!=.
egen std_pe_ppvtr3_5=std(pe_ppvt_r3) if pe_ppvt_r3>=60 & pe_ppvt_r3<72 & pe_ppvt_r3!=.
egen std_pe_ppvtr3_6=std(pe_ppvt_r3) if pe_ppvt_r3>=72                 & pe_ppvt_r3!=.
***
replace std_pe_ppvtr3=std_pe_ppvtr3_3 if std_pe_ppvtr3_3!=.
replace std_pe_ppvtr3=std_pe_ppvtr3_4 if std_pe_ppvtr3_4!=.
replace std_pe_ppvtr3=std_pe_ppvtr3_5 if std_pe_ppvtr3_5!=.
replace std_pe_ppvtr3=std_pe_ppvtr3_6 if std_pe_ppvtr3_6!=.

gen  std_et_ppvtr3=.
egen std_et_ppvtr3_3=std(et_ppvt_r3)  if et_ppvt_r3<48                    & et_ppvt_r3!=.
egen std_et_ppvtr3_4=std(et_ppvt_r3)  if et_ppvt_r3>=48 & et_ppvt_r3<60   & et_ppvt_r3!=.
egen std_et_ppvtr3_5=std(et_ppvt_r3)  if et_ppvt_r3>=60 & et_ppvt_r3<72   & et_ppvt_r3!=.
egen std_et_ppvtr3_6=std(et_ppvt_r3)  if et_ppvt_r3>=72 & et_ppvt_r3<84   & et_ppvt_r3!=.
egen std_et_ppvtr3_7=std(et_ppvt_r3)  if et_ppvt_r3>=84 & et_ppvt_r3<96   & et_ppvt_r3!=.
egen std_et_ppvtr3_8=std(et_ppvt_r3)  if et_ppvt_r3>=96 & et_ppvt_r3<108  & et_ppvt_r3!=.
egen std_et_ppvtr3_9=std(et_ppvt_r3)  if et_ppvt_r3>=108 & et_ppvt_r3<120 & et_ppvt_r3!=.
egen std_et_ppvtr3_10=std(et_ppvt_r3) if et_ppvt_r3>=120 & et_ppvt_r3<132 & et_ppvt_r3!=.
egen std_et_ppvtr3_11=std(et_ppvt_r3) if et_ppvt_r3>=132 & et_ppvt_r3<144 & et_ppvt_r3!=.
egen std_et_ppvtr3_12=std(et_ppvt_r3) if et_ppvt_r3>=144 & et_ppvt_r3<156 & et_ppvt_r3!=.
egen std_et_ppvtr3_13=std(et_ppvt_r3) if et_ppvt_r3>=156 & et_ppvt_r3<168 & et_ppvt_r3!=.
egen std_et_ppvtr3_14=std(et_ppvt_r3) if et_ppvt_r3>=168 & et_ppvt_r3<180 & et_ppvt_r3!=.
egen std_et_ppvtr3_15=std(et_ppvt_r3) if et_ppvt_r3>=180                  & et_ppvt_r3!=.
***
replace std_et_ppvtr3=std_et_ppvtr3_3  if std_et_ppvtr3_3!=.
replace std_et_ppvtr3=std_et_ppvtr3_4  if std_et_ppvtr3_4!=.
replace std_et_ppvtr3=std_et_ppvtr3_5  if std_et_ppvtr3_5!=.
replace std_et_ppvtr3=std_et_ppvtr3_6  if std_et_ppvtr3_6!=.
replace std_et_ppvtr3=std_et_ppvtr3_7  if std_et_ppvtr3_7!=.
replace std_et_ppvtr3=std_et_ppvtr3_8  if std_et_ppvtr3_8!=.
replace std_et_ppvtr3=std_et_ppvtr3_9  if std_et_ppvtr3_9!=.
replace std_et_ppvtr3=std_et_ppvtr3_10 if std_et_ppvtr3_10!=.
replace std_et_ppvtr3=std_et_ppvtr3_11 if std_et_ppvtr3_11!=.
replace std_et_ppvtr3=std_et_ppvtr3_12 if std_et_ppvtr3_12!=.
replace std_et_ppvtr3=std_et_ppvtr3_13 if std_et_ppvtr3_13!=.
replace std_et_ppvtr3=std_et_ppvtr3_14 if std_et_ppvtr3_14!=.
replace std_et_ppvtr3=std_et_ppvtr3_15 if std_et_ppvtr3_15!=.

***Creating PPVT at around age 5 for all children
gen std_ppvt_c=.
replace std_ppvt_c=std_et_ppvtr3 if sibling==1 & country==2
replace std_ppvt_c=std_pe_ppvtr3 if sibling==1 & country==1
replace std_ppvt_c=std_et_ppvtr2 if sibling==0 & country==2
replace std_ppvt_c=std_pe_ppvtr2 if sibling==0 & country==1

*** STANDARDIZING PPVT FROM ROUND 3 (FOR INDEX CHILDREN)
gen  std_pe_cppvtr3=.
egen std_pe_cppvtr3_8=std(pe_cppvt_r3) if pe_cppvt_r3<96  & pe_cppvt_r3!=.
egen std_pe_cppvtr3_9=std(pe_cppvt_r3) if pe_cppvt_r3>=96 & pe_cppvt_r3!=.
***
replace std_pe_cppvtr3=std_pe_cppvtr3_8 if std_pe_cppvtr3_8!=.
replace std_pe_cppvtr3=std_pe_cppvtr3_9 if std_pe_cppvtr3_9!=.
***Index R3 Ethiopia
gen  std_et_cppvtr3=.
egen std_et_cppvtr3_8=std(et_cppvt_r3) if et_cppvt_r3<96  & et_cppvt_r3!=.
egen std_et_cppvtr3_9=std(et_cppvt_r3) if et_cppvt_r3>=96 & et_cppvt_r3!=.
***
replace std_et_cppvtr3=std_et_cppvtr3_8 if std_et_cppvtr3_8!=.
replace std_et_cppvtr3=std_et_cppvtr3_9 if std_et_cppvtr3_9!=.

***Creatitng PPVT at around age 8 for all children
gen std_ppvt_c2=.
replace std_ppvt_c2=ppvtz_r4      if sibling==1 & country==2
replace std_ppvt_c2=ppvtz_r4      if sibling==1 & country==1
replace std_ppvt_c2=std_et_cppvtr3 if sibling==0 & country==2
replace std_ppvt_c2=std_pe_cppvtr3 if sibling==0 & country==1

***Index R4 Peru, PPVT
gen  std_pe_cppvtr4=.
egen std_pe_cppvtr4_11=std(ppvtraw_r4) if ppvtraw_r4<144  & ppvtraw_r4!=. & country==1
egen std_pe_cppvtr4_12=std(ppvtraw_r4) if ppvtraw_r4>=144 & ppvtraw_r4!=. & country==1
***
replace std_pe_cppvtr4=std_pe_cppvtr4_11 if std_pe_cppvtr4_11!=.
replace std_pe_cppvtr4=std_pe_cppvtr4_12 if std_pe_cppvtr4_12!=.

***Index R4 Ethiopia, PPVT
gen  std_et_cppvtr4=.
egen std_et_cppvtr4_11=std(ppvtraw_r4) if ppvtraw_r4<144  & ppvtraw_r4!=. & country==2
egen std_et_cppvtr4_12=std(ppvtraw_r4) if ppvtraw_r4>=144 & ppvtraw_r4!=. & country==2
***
replace std_et_cppvtr4=std_et_cppvtr4_11 if std_et_cppvtr4_11!=.
replace std_et_cppvtr4=std_et_cppvtr4_12 if std_et_cppvtr4_12!=.

*** PPVT at age 12 for index children
gen std_ppvt_r4=.
replace std_ppvt_r4=std_et_cppvtr4 if sibling==0 & country==2
replace std_ppvt_r4=std_pe_cppvtr4 if sibling==0 & country==1

***Dropping outliers
replace std_ppvt_c=. if std_ppvt_c<-4 & std_ppvt_c!=.
replace std_ppvt_c=. if std_ppvt_c>4  & std_ppvt_c!=.

replace std_ppvt_c2=. if std_ppvt_c2<-4 & std_ppvt_c2!=.
replace std_ppvt_c2=. if std_ppvt_c2>4  & std_ppvt_c2!=.

replace ppvtz_r4=. if ppvtz_r4<-4 & ppvtz_r4!=.
replace ppvtz_r4=. if ppvtz_r4>4  & ppvtz_r4!=.

bysort childid sibling: egen n=max(task) /* keep only paired-siblings who answer all tasks*/
drop if n!=4 /*22 obs*/
drop n
est clear

gen sib_y=0
gen sib_o=0
replace sib_y=1 if sibling==1 & sibyounger==1
replace sib_o=1 if sibling==1 & sibyounger==0 

gen zhfa_c=.
replace zhfa_c=zhfa_r3 if sibling==1
replace zhfa_c=zhfa_r2 if sibling==0

gen stunting_c=.
replace stunting_c=stunting_r3 if sibling==1
replace stunting_c=stunting_r2 if sibling==0

gen zhfaxsib_y=zhfa_c*sib_y
gen zhfaxsib_o=zhfa_c*sib_o
gen zhfaxage=zhfa_c*chage_r4

gen stuntingxsib_y=stunting_c*sib_y
gen stuntingxsib_o=stunting_c*sib_o
gen stuntingxage  =stunting_c*chage_r4

gen zhfaxfem=zhfa_c*female

gen stuntingxfem=stunting_c*female

gen chage_r4_2=chage_r4*chage_r4

label var stunting_c     "Stunted"
label var stuntingxsib_y "Stunted x younger sib"
label var stuntingxsib_o "Stunted x older sib"
label var stuntingxfem   "Stunted x female"

label var zhfa_c         "Height for age"
label var zhfaxsib_y     "Height for age x younger sib"
label var zhfaxsib_o     "Height for age x older sib"
label var zhfaxfem       "Height for age x female"

label var chage_r4     "Age in months, r4"
label var chage_r4_2   "Age in months squared, r4"
label var female       "Child is female"
label var dm_educ2     "Maternal edu: complete primary"
label var dm_educ3     "Maternal edu: complete secondary"
label var dm_educ4     "Maternal edu: complete tertiary"
label var urban_r1     "Urban area, r1"
label var hhsize_r2    "Household size, r2" 
label var mom_spanish  "Maternal native tongue: spanish"
label var mom_oromifa  "Maternal native tongue: oromifah" 
label var mom_tigrina  "Maternal native tongue: tigrina"
label var mom_other    "Maternal native tongue: other"
label var wi_r1q2      "Wealth index quintile 2"
label var wi_r1q3      "Wealth index quintile 3"
label var wi_r1q4      "Wealth index quintile 4"
label var wi_r1q5      "Wealth index quintile 5"

***Index children
gen     zhfa_5 =zhfa_r2     if (zhfa_r2>=-6 & zhfa_r2<=6) & sibling==0                 & country==2 
gen     zhfa_12=zhfa_r4     if (zhfa_r4>=-6 & zhfa_r4<=6) & sibling==0                 & country==2 

***Older siblings
replace zhfa_12=zhfa_r3 if (zhfa_r3>=-6 | zhfa_r3<=6) & sibling==1 & sibyounger==0 & country==2 

***PPVT
gen missing_ppvt=.
replace missing_ppvt=0 if country==2 & ppvtz_r4!=.
replace missing_ppvt=1 if country==2 & ppvtz_r4==. 
label var missing_ppvt "Missing PPVT"
tab missing_ppvt
replace ppvtz_r4=10000 if ppvtz_r4==.

***Socio emotional outcomes
gen missing_pride_r4=.
replace missing_pride=0 if country==2 & pride_index_r4!=.
replace missing_pride=1 if country==2 & pride_index_r4==. 
label var missing_pride "Missing pride index"
tab missing_pride
replace pride_index_r4=10000 if pride_index_r4==.

gen missing_agency_r4=.
replace missing_agency=0 if country==2 & agency_index_r4!=.
replace missing_agency=1 if country==2 & agency_index_r4==. 
label var missing_agency "Missing agency index"
tab missing_agency
replace agency_index_r4=10000 if agency_index_r4==.

gen missing_sesteem_r4=.
replace missing_sesteem=0 if country==2 & sesteem_index_r4!=.
replace missing_sesteem=1 if country==2 & sesteem_index_r4==. 
label var missing_sesteem "Missing self-esteem index"
tab missing_sesteem
replace sesteem_index_r4=10000 if sesteem_index_r4==.

foreach x of varlist zhfa_5 zhfa_12 pride_index_r4 agency_index_r4 sesteem_index_r4 ppvtz_r4 missing_ppvt ///
hsleep_r4 hcare_r4 hchore_r4 htask_r4 hwork_r4 hschool_r4 hstudy_r4 hplay_r4 female ///
dm_educ2 dm_educ3 dm_educ4 urban_c hhsize_c mom_oromifa mom_tigrina mom_other wi_cq2 wi_cq3 wi_cq4 wi_cq5 {
	gen `x'xage  =. 
	gen `x'xage2 =.
	replace `x'xage  =`x'*chage_r2           if sibling==0 
	replace `x'xage  =`x'*chage_r3           if sibling==1
	replace `x'xage2 =`x'*chage_r2*chage_r2  if sibling==0
	replace `x'xage2 =`x'*chage_r3*chage_r3  if sibling==1
}

forvalues x= 1/20 {
	gen clust`x'_=0
	replace clust`x'_=1 if clustid_r1==`x'
}
 
***Requires for pooled sample estimations 
replace mom_spanish=0 if country==2 
replace mom_oromifa=0 if country==1  
replace mom_tigrina=0 if country==1 
replace mom_other=0   if country==1 

***Different cluster IDs are required for the pooled sample of two countries
replace clustid_r1=clustid_r1+100 if country==2

global country   mom_spanish mom_oromifa mom_tigrina mom_other

global nut    stunting_c
global nutage stunting_c stuntingxage chage_r4 chage_r4_2 
global nutsex stunting_c i.female*stunting_c

******************************
*** Table 4, panel A (using unadjusted stunting, excluding older siblings)
******************************
preserve
drop if sibyounger==0
***Pooled sample
areg $task3 $nut $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2
areg $task1 $nut $control0 $control2q $country $alltask $btask1  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb) 
estimates store reg1
areg $task4 $nut $control0 $control2q $country $alltask $btask4  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg4

***PERU
areg $task3 $nut $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p
areg $task1 $nut $control0 $control2q $country1 $alltask $btask1  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb) 
estimates store reg1p
areg $task4 $nut $control0 $control2q $country1 $alltask $btask4  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg4p

***ETHIOPIA
areg $task3 $nut $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e
areg $task1 $nut $control0 $control2q $country2 $alltask $btask1  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg1e
areg $task4 $nut $control0 $control2q $country2 $alltask $btask4  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg4e

xml_tab reg5 reg2 reg1 reg4 reg5p reg2p reg1p reg4p reg5e reg2e reg1e reg4e, /// 
save("$output\reg_071023_3.xls") replace tstat below sheet("Table4A") stats(N r2_a)
restore

******************************
*** Table 5, panel A (baseline)
******************************
global nut    stunting_c
global ppvt  

preserve
drop if sibyounger==0 
keep if std_ppvt_c!=. & std_ppvt_c2!=.
***Pooled
areg $task3 $nut $ppvt $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $ppvt $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $ppvt $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $ppvt $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $ppvt $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $ppvt $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("Table5A_12") stats(N r2_a)
restore

******************************
*** Table 5, panel A (controlling for PPVT at age 5)
******************************
global nut    stunting_c
global ppvt std_ppvt_c

preserve
drop if sibyounger==0 
keep if std_ppvt_c!=. & std_ppvt_c2!=.
***Pooled
areg $task3 $nut $ppvt $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $ppvt $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $ppvt $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $ppvt $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $ppvt $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $ppvt $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("Table5A_34") stats(N r2_a)
restore

******************************
*** Table 5, panel A (controlling for PPVT at age 8)
******************************
global nut    stunting_c
global ppvt std_ppvt_c2

preserve
drop if sibyounger==0 
keep if std_ppvt_c!=. & std_ppvt_c2!=.
***Pooled
areg $task3 $nut $ppvt $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $ppvt $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $ppvt $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $ppvt $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $ppvt $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $ppvt $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("Table5A_56") stats(N r2_a)
restore

******************************
*** Table C5, age 9 or less
******************************
preserve
drop if sibyounger==0
keep if age<=9 & age!=.
***Pooled sample
areg $task3 $nut $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC5_Age89") stats(N r2_a)
restore

******************************
*** Table C5, age 10 to 11
******************************
preserve
drop if sibyounger==0
keep if age>=10 & age<=11 & age!=.
***Pooled sample
areg $task3 $nut $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC5_Age1011") stats(N r2_a)
restore

******************************
*** Table C5, age 12 to 13
******************************
preserve
drop if sibyounger==0
keep if age>=12 & age!=.
***Pooled sample
areg $task3 $nut $control0 $control2q $country $alltask $btask3  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg $task2 $nut $control0 $control2q $country $alltask $btask2  $cluster_r1 if $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2

***PERU
areg $task3 $nut $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5p
areg $task2 $nut $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2p

***ETHIOPIA
areg $task3 $nut $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5e
areg $task2 $nut $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2  & $sample2 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2e

xml_tab reg5 reg2 reg5p reg2p reg5e reg2e, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC5_Age1213") stats(N r2_a)
restore

******************************
*** Table C4: Column 1 (MISSING PPVT IN R4 & WM)
******************************
gen ppvt_r4=0
replace ppvt_r4=1 if ppvtz_r4!=.
replace ppvt_r4=0 if ppvtz_r4==10000

preserve
areg ppvt_r4 $task3 $control0 $control2q $country  $alltask $btask3  $cluster_r1 if              $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg1
areg ppvt_r4 $task3 $control0 $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2
areg ppvt_r4 $task3 $control0 $control2q $country2 $alltask $btask3  $cluster_r1 if country==2 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg3a

xml_tab reg1 reg2 reg3a, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC4_WM") stats(N r2_a)
restore

******************************
*** Table C4: Column 2 (MISSING PPVT IN R4 & IC)
******************************

preserve
areg ppvt_r4 $task2 $control0 $control2q $country  $alltask $btask2  $cluster_r1 if              $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg4
areg ppvt_r4 $task2 $control0 $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg ppvt_r4 $task2 $control0 $control2q $country2 $alltask $btask2  $cluster_r1 if country==2 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg6

xml_tab reg4 reg5 reg6, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC4_PPVT_IC") stats(N r2_a)
restore


******************************
*** Table C4: Column 3 (MISSING PPVT AT AGE 5 & WM)
******************************
gen ppvt_age5=0
replace ppvt_age5=1 if std_ppvt_c!=.
global control0n  chage_r2 female dm_educ2 dm_educ3 dm_educ4 urban_c hhsize_c

preserve
drop if sibling==1
areg ppvt_age5 $task3 $control0n $control2q $country  $alltask $btask3  $cluster_r1 if              $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg1
areg ppvt_age5 $task3 $control0n $control2q $country1 $alltask $btask3  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg2
areg ppvt_age5 $task3 $control0n $control2q $country2 $alltask $btask3  $cluster_r1 if country==2 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg3a

xml_tab reg1 reg2 reg3a, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC4_age5_WM") stats(N r2_a)
restore

******************************
*** Table C4: Column 4 (MISSING PPVT AT AGE 5 & IC)
******************************

preserve
drop if sibling==1
areg ppvt_age5 $task2 $control0n $control2q $country  $alltask $btask2  $cluster_r1 if              $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg4
areg ppvt_age5 $task2 $control0n $control2q $country1 $alltask $btask2  $cluster_r1 if country==1 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg5
areg ppvt_age5 $task2 $control0n $control2q $country2 $alltask $btask2  $cluster_r1 if country==2 & $sample1 , vce(cluster clustid_r1) absorb($absorb)
estimates store reg6

xml_tab reg4 reg5 reg6, /// 
save("$output\reg_071023_3.xls") append tstat below sheet("TableC4_age5_IC") stats(N r2_a)
restore
